public class ProxySearcher  implements ISearcher {
    private ISearcher realSearcher;
    private AccessValidator accessValidator;
    private Logger logger;

    public ProxySearcher(ISearcher realSearcher, AccessValidator accessValidator, Logger logger) {
        this.realSearcher = realSearcher;
        this.accessValidator = accessValidator;
        this.logger = logger;
    }

    @Override
    public void search(String query) {
        if (!isUserValid()) {
            System.out.println("用户无效，访问被拒绝。");
            return;
        }

        logger.log("用户正在搜索：" + query);

        realSearcher.search(query);
    }

    private boolean isUserValid() {

        String username = "admin";
        String password = "admin";
        return accessValidator.validate(username, password);
    }
}